﻿Imports System.Collections.ObjectModel

Public MustInherit Class ProductionSymbol
    Implements IEquatable(Of ProductionSymbol)

    Public MustOverride ReadOnly Property IsNullable() As Boolean
    Public MustOverride ReadOnly Property First() As IEnumerable(Of Terminal)

    Private m_index As Integer
    Friend ReadOnly Property Index() As Integer
        Get
            Return m_index
        End Get
    End Property

    Private m_debugName As String
    Public Property DebugName() As String
        Get
            Return m_debugName
        End Get
        Set(ByVal value As String)
            m_debugName = value
        End Set
    End Property

    Protected Sub New(ByVal index As Integer)
        m_index = index
    End Sub

    Public Overrides Function GetHashCode() As Integer
        Return (m_index << 8) Xor Me.GetType.GetHashCode()
    End Function

    Public Overrides Function Equals(ByVal obj As Object) As Boolean
        Dim other = TryCast(obj, ProductionSymbol)

        Return Equals(other)
    End Function

    Public Overloads Function Equals(ByVal other As ProductionSymbol) As Boolean Implements IEquatable(Of ProductionSymbol).Equals
        If other Is Nothing Then Return False
        If Not Me.GetType().Equals(other.GetType) Then Return False

        Return Me.m_index = other.m_index
    End Function

    Public Overrides Function ToString() As String
        Return If(DebugName, "NO_NAME")
    End Function
End Class
